package main

import "fmt"

// Author : CSR丶WARRIOR
// Time ： 2020/10/14  17:41
// TOOLS : GoLand
// FILENAME : KeyAndValue.go
// STATEMENT: map键与值

func main() {
	deleteKey()
}

func getValueByKey() {
	var m map[int]string = map[int]string{1: "王五", 2: "李四"}
	value, ok := m[2]
	if ok {
		fmt.Println(value) //李四
	} else {
		fmt.Println("key 不存在")
	}
}

func getValueByFor() {
	var m map[int]string = map[int]string{1: "张三", 2: "李四", 3: "王五"}
	for i, i2 := range m {
		fmt.Printf("%d = %s\t", i, i2)
		//1 = 张三	2 = 李四	3 = 王五
	}
}

func deleteKey() {
	var m map[int]string = map[int]string{1: "张三", 2: "李四", 3: "王五"}
	delete(m, 2)
	fmt.Println(m) //map[1:张三 3:王五]
}
